﻿package Component {
	
	import Map.Zone;
	
	public class Melee extends Map {
		
		private var zone0:Zone;
		private var zone1:Zone;
		private var zone2:Zone;
		private var zone3:Zone;
		
		public function Melee() {
		}
		
		public override function initialize(context:Context) {
			super.initialize(context);
			
			// register spawns
			builders.push(spawn0);
			attach(spawn0.avatar);
			spawn0.avatar.colorize(0);
			builders.push(spawn1);
			attach(spawn1.avatar);
			spawn1.avatar.colorize(1);
			builders.push(spawn2);
			attach(spawn2.avatar);
			spawn2.avatar.colorize(2);
			builders.push(spawn3);
			attach(spawn3.avatar);
			spawn3.avatar.colorize(3);

			// attach avatars to players
			context.match.getPlayer(0).avatar = spawn0.avatar;
			context.match.getPlayer(1).avatar = spawn1.avatar;
			context.match.getPlayer(2).avatar = spawn2.avatar;
			context.match.getPlayer(3).avatar = spawn3.avatar;
						
			zone0 = new Zone(context,2);
			builders.push(zone0);
			zone1 = new Zone(context,2);
			builders.push(zone1);
			zone2 = new Zone(context,2);
			builders.push(zone2);
			zone3 = new Zone(context,2);
			builders.push(zone3);

			// attach all blocks to zone
			var block:BonusBlock;

            // the square for the zones
			for (var x:int = 2; x < 9; x++)
			{
				for (var y:int = 2; y < 9; y++)
				{
                    // if x or y is not pair
                    if ((x % 2 == 0) && (y % 2 == 0))
						continue;
						
                    if ( (x > 6) && (y > 6) ) {
                        continue;
					}
					
                    attach(zone0.createBonusBlock(x, y));
                    attach(zone1.createBonusBlock(20 - x, y));
                    attach(zone2.createBonusBlock(x, 20 - y));
                    attach(zone3.createBonusBlock(20 - x, 20 - y));
                }
			}
			
			zone0.initialize();
			zone1.initialize();
			zone2.initialize();
			zone3.initialize();
			
			slab0.trap = mc_trap;
			slab1.trap = mc_trap;
			slab2.trap = mc_trap;
			slab3.trap = mc_trap;
		}
	}
	
}
